package com.thh.excel;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URL;

public class SimpleDemo {


    public static void main(String[] args) throws IOException {
        SimpleDemo simpleDemo = new SimpleDemo();
        simpleDemo.testExcel();
    }
    public void testExcel() throws IOException {

        //创建工作簿
        Workbook workbook =  new SXSSFWorkbook();
        //创建工作表
        Sheet sheet = workbook.createSheet();
        //创建行  列
        Row row = sheet.createRow(0);
        Cell cell = row.createCell(0);
        cell.setCellValue("helloWord");
        URL urlRoot = SimpleDemo.class.getResource("/");
        String RootDir = urlRoot.getFile();
        File dest = new File(RootDir+"\\out.xlsx");
        OutputStream   outputStream = new FileOutputStream(dest);
        if (!dest.exists()){
            dest.createNewFile();
        }
        workbook.write(outputStream);
        outputStream.close();
    }
}